package week2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Day6 {




    //1.
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            String s1 = in.nextLine();
            String s2 = in.nextLine();
            StringBuilder ret = new StringBuilder();
            for(int i=0;i<s1.length();i++) {//遍历s1
                char ch = s1.charAt(i);
                //判断该字符是否要去除
                int j=0;
                for(;j<s2.length();j++) {
                    char tmp = s2.charAt(j);
                    if(tmp == ch && ch != ' ') {
                        break;
                    }
                }
                if(j==s2.length()) {
                    ret.append(ch);
                }
            }
            System.out.println(ret.toString());
        }
    }




    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            String s =  in.next();
            long ret = 0;//记录shy的数目
            //存s h y的下标
            List<Integer> list1 = new ArrayList<>();
            List<Integer> list2 = new ArrayList<>();
            List<Integer> list3 = new ArrayList<>();
            for(int i=0;i<s.length();i++) {
                char ch  = s.charAt(i);
                if(ch=='s') {
                    list1.add(i);
                }else if(ch=='h') {
                    list2.add(i);
                }else if(ch=='y') {
                    list3.add(i);
                }
            }
            int i=0;
            int j=0;
            int k=0;
            int a=list1.size();
            int b=list1.size();
            int c=list1.size();
            for(;i<a;i++) {
                int x = list1.get(i);
                for(;j<b;j++) {
                    int y = list2.get(j);
                    if(y>x) {
                        for(;k<c;k++) {
                            int z = list3.get(k);
                            if(z>y) {
                                ret += c-k;
                                break;
                            }
                        }

                    }
                }
            }
            System.out.println(ret);
        }
    }
}
